﻿<template>
  <div class="car_car-container">
    <el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="车型名">
          <el-input v-model="queryParams.title" clearable="" placeholder="请输入车型名" />

        </el-form-item>
        <el-form-item label="品牌">
          <!-- <el-input v-model="queryParams.pid" clearable="" placeholder="请选择" /> -->

          <el-select clearable filterable v-model="queryParams.pid" placeholder="请选择品牌">
								<el-option v-for="(item, index) in car_carPidDropdown" :key="index"
									:value="item.value" :label="item.label" />
							</el-select>

        </el-form-item>
        <el-form-item>
          <el-button-group>
            <el-button type="primary" icon="ele-Search" @click="handleQuery" v-auth="'car_car:page'"> 查询 </el-button>
            <el-button icon="ele-Refresh" @click="() => queryParams = {}"> 重置 </el-button>

          </el-button-group>

        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="ele-Plus" @click="openAddcar_car" v-auth="'car_car:add'"> 新增 </el-button>

        </el-form-item>

      </el-form>
    </el-card>
    <el-card class="full-table" shadow="hover" style="margin-top: 8px">

      <!-- <div v-loading="state.treeLoading">
				<div class="tree-head">
					<div class="tree-head-check"><el-checkbox v-model="state.treeCheckAll" @change="onCheckAllChange"></el-checkbox></div>
					<div class="tree-head-one">商品 ID</div>
					<div style="flex: 1; display: flex">
						<div class="tree-head-two">车名称</div>
						<div class="tree-head-three">描述</div>
					</div>
				</div>
				<el-tree :data="state.treeTableData" show-checkbox node-key="id" ref="treeTableRef" :props="state.treeDefaultProps" @check="onCheckTree">
					<template #default="{ node, data }">
						<span class="tree-custom-node">
							<span style="flex: 1">{{ node.label }}</span>
							<span v-if="data.isShow" style="flex: 1; display: flex">
								<span style="flex: 1">{{ data.label1 }}</span>
								<span style="flex: 1">{{ data.label2 }}</span>
							</span>
						</span>
					</template>
</el-tree>
</div> -->

      <el-table :data="tableData" style="width: 100%" v-loading="loading" tooltip-effect="light" row-key="id" border="">
        <el-table-column type="index" label="序号" width="55" align="center" fixed="" />
        <el-table-column prop="title" label="车型名" width="200" fixed="" show-overflow-tooltip="" />
        <el-table-column prop="caseCount" label="案例数量" width="200" fixed="" show-overflow-tooltip="" />
        <el-table-column prop="pTitle" label="品牌" width="200" fixed="" show-overflow-tooltip="" />
        <el-table-column label="操作" width="140" align="center" fixed="right" show-overflow-tooltip=""
          v-if="auth('car_car:edit') || auth('car_car:delete')">
          <template #default="scope">
            <el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditcar_car(scope.row)"
              v-auth="'car_car:edit'"> 编辑 </el-button>
            <el-button icon="ele-Delete" size="small" text="" type="primary" @click="delcar_car(scope.row)"
              v-auth="'car_car:delete'"> 删除 </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination v-model:currentPage="tableParams.page" v-model:page-size="tableParams.pageSize"
        :total="tableParams.total" :page-sizes="[10, 20, 50, 100]" small="" background=""
        @size-change="handleSizeChange" @current-change="handleCurrentChange"
        layout="total, sizes, prev, pager, next, jumper" />
      <editDialog ref="editDialogRef" :title="editcar_carTitle" @reloadTable="handleQuery" />
    </el-card>
  </div>
</template>

<script lang="ts" setup="" name="car_car">
import { ref } from "vue";
import { ElMessageBox, ElMessage } from "element-plus";
import { auth } from '/@/utils/authFunction';
//import { formatDate } from '/@/utils/formatTime';

import editDialog from '/@/views/main/car_car/component/editDialog.vue'

import { pagecar_tag, deletecar_tag ,car_tagPidDropdown} from '/@/api/main/car_tag';
var typeenum = 1;


const editDialogRef = ref();
const loading = ref(false);
const tableData = ref<any>
  ([]);
const queryParams = ref<any>
  ({});
const tableParams = ref({
  page: 1,
  pageSize: 10,
  total: 0,
});
const editcar_carTitle = ref("");


// 查询操作
const handleQuery = async () => {
  loading.value = true;
 
  queryParams.value.type = typeenum;

   if(queryParams.value.pid=="")
{
 
  delete queryParams.value.pid;
}

  var res = await pagecar_tag(Object.assign(queryParams.value, tableParams.value));
  tableData.value = res.data.result?.items ?? [];
  tableParams.value.total = res.data.result?.total;
  loading.value = false;
};

// 打开新增页面
const openAddcar_car = () => {
  editcar_carTitle.value = '添加车型';
  editDialogRef.value.openDialog({});
};

// 打开编辑页面
const openEditcar_car = (row: any) => {
  editcar_carTitle.value = '编辑车型';
  editDialogRef.value.openDialog(row);
};

// 删除
const delcar_car = (row: any) => {
  ElMessageBox.confirm(`确定要删除吗?`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      await deletecar_tag(row);
      handleQuery();
      ElMessage.success("删除成功");
    })
    .catch(() => { });
};

// 改变页面容量
const handleSizeChange = (val: number) => {
  tableParams.value.pageSize = val;
  handleQuery();
};

// 改变页码序号
const handleCurrentChange = (val: number) => {
  tableParams.value.page = val;
  handleQuery();
};

const car_carPidDropdown = ref<any>([]);
const getcar_carPidrDropdownList = async () => {
  let list = await car_tagPidDropdown({type:typeenum,pid:0});
  car_carPidDropdown.value = list.data.result ?? [];
};
getcar_carPidrDropdownList();


handleQuery();
</script>




<style scoped lang="scss">
.tree-container {
  .tree-head {
    height: 48px;
    line-height: 48px;
    border: 1px solid var(--next-border-color-light);
    border-bottom: none;
    display: flex;
    padding-right: 8px;
    font-weight: bold;
    color: #909399;

    .tree-head-check {
      width: 38px;
      text-align: right;
    }

    .tree-head-one,
    .tree-head-two,
    .tree-head-three {
      flex: 1;
    }

    .tree-head-one {
      padding-left: 8px;
    }
  }

  .el-tree {
    overflow: hidden;
    border-bottom: 1px solid var(--next-border-color-light);

    .tree-custom-node {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding-right: 8px;
      width: 100%;
    }

    &:deep(.el-tree-node) {
      border: 1px solid var(--next-border-color-light);
      border-bottom: none;
      color: #606266;

      .el-tree-node__content {
        line-height: 57px !important;
        height: 57px !important;
      }

      .el-tree-node__children {
        .el-tree-node {
          border: none;
        }

        .el-tree-node__content {
          border-top: 1px solid var(--next-border-color-light);
        }
      }
    }
  }
}
</style>
